<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
</head>
<body>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap/css/default.css">

<!-- Custom styles for this template -->
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/dashboard.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/adminnav.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap/css/style.css">

<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.js"></script>
<script src="${pageContext.request.contextPath}/static/js/functions.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="${pageContext.request.contextPath}/static/css/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/static/css/bootstrap/js/prettify.min.js"></script>
<script src="${pageContext.request.contextPath}/static/css/bootstrap/js/multiselect.min.js"></script>

<script type="text/javascript">
    function updatePic() {
        if ($("#updatePicBut").val() == "修改商品图片") {
            $("#goodsPicFile").attr("type", "file");
            $("#updatePicBut").val("取消修改商品图片");
        } else {
            $("#goodsPicFile").attr("name", "");
            $("#goodsPicFile").attr("type", "hidden");
            $("#updatePicBut").val("修改商品图片");
        }
    }
</script>

<c:import url="../common/adminTopNav.jsp"/>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">

            <c:import url="../common/adminLeftNav.jsp"/>

        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <%--content--%>

            <h2 class="sub-header">${empty product?"添加":"修改"}商品</h2>
            <div class="col-sm-6 col-sm-offset-3 col-md-8 col-md-offset-2">

                <form class="form" role="form" method="post"
                      action="${pageContext.request.contextPath}/product/addOrUpdateProduct"
                      enctype="multipart/form-data">

                    <input type="hidden" id="goodsId" name="pid" value="${product.pid}"/>
                    <c:if test="${not empty product.url}">
                        <img src="${product.url}" width="242" height="200">
                    </c:if>
                    <div class="form-group">
                        <label for="cateId"> 所属商品类别</label>
                        <select class="form-control input-sm" name="cid" id="cateId">
                            <c:forEach items="${categoryList}" var="category">
                                <option value="${category.cid}">${category.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="goodsName"> 商品名称 </label>
                        <input class="form-control" name="name" id="goodsName" value="${product.name}" type="text"
                               placeholder="商品名称" required/>
                    </div>
                    <div class="form-group">
                        <label for="goodsDisc"> 商品描述 </label>
                        <textarea class="form-control" name="description" id="goodsDisc" rows="3" placeholder="商品描述"

                                  required>${product.description}</textarea>
                    </div>
                    <div class="form-group">
                        <label for="goodsPrice"> 商品原价</label>
                        <input class="form-control" name="price" id="goodsPrice" value="${product.price}" type="text"
                               placeholder="商品原价" required/>
                    </div>
                    <div class="form-group">
                        <label for="goodsDiscount"> 商品折后价格 </label>
                        <input class="form-control" name="offPrice" id="goodsDiscount" value="${product.offPrice}"
                               type="text"
                               placeholder="商品折后价格" required/>
                    </div>
                    <div class="form-group">
                        <label for="goodsStock"> 商品库存 </label>
                        <input class="form-control" name="store" id="goodsStock" value="${product.store}" type="number"
                               placeholder="商品库存" required/>
                    </div>
                    <div class="form-group">
                        <label for="goodsOrigin"> 商品产地 </label>
                        <input class="form-control" name="origin" id="goodsOrigin" value="${product.origin}" type="text"
                               placeholder="商品产地" required/>
                    </div>
                    <div class="form-group">
                        <label for="goodsMaterial"> 商品材质</label>
                        <input class="form-control" name="quality" id="goodsMaterial" value="${product.quality}"
                               type="text"
                               placeholder="商品材质" required/>
                    </div>
                    <div class="form-group">
                        <label for="goodsPostalfee"> 商品运费</label>
                        <input class="form-control" name="freight" id="goodsPostalfee" value="${product.freight}"
                               type="number"
                               placeholder="商品运费" required/>
                    </div>
                    <div class="form-group">
                        <label for="goodsDate"> 商品入货日期（格式yyyy-mm-dd，如2016-01-01）</label>

                        <input class="form-control" name="date" id="goodsDate"
                               value="<c:if test="${not empty today and empty product.date}"><fmt:formatDate value="${today}" pattern="yyyy-MM-dd"/></c:if>
<c:if test="${not empty product.date}"><fmt:formatDate value="${product.date}" pattern="yyyy-MM-dd"/></c:if>"
                               type="date" placeholder="商品入货日期" required/>
                    </div>
                    <div class="form-group" id="goodsPicDiv">
                        <label for="goodsPic"> 商品图片（图片规格：242*200）</label>
                        <c:if test="${not empty product.url}">
                            <input class="form-control btn-info" type="button" id="updatePicBut" value="修改商品图片"
                                   onclick="updatePic()"/>
                        </c:if>
                        <input class="form-control" name="picture" id="goodsPicFile" type="hidden" required/>
                    </div>
                    <input type="hidden" name="url" value="${product.url}"/>
                    <button class="btn btn-primary" type="submit">确定</button>
                    <button class="btn btn-default" type="reset">重置</button>
                </form>
            </div>

        </div>
    </div>
</div>

<c:import url="../common/adminFooter.jsp"/>

</body>
</html>